﻿/******************************************************************************
* File description: Energyspectrum.qml
* Function: 能谱图维护
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
ApplicationWindow {

    id: root

    title: "能谱维护"

    property int showDetails: 1

    width: 800*dp
    height: 600*dp
    minimumWidth: 800*dp
    minimumHeight: 600*dp


    color: Qt.rgba(233/255, 230/255, 224/255, 1)

    // 切换按钮
    property real buttonH: 34*dp
    property real buttonW: 90*dp
    property real chartY: layout_rect.y

    Component.onCompleted: {
        chart.refreshData()
    }

    onClosing: {
        CMaintenance.operationCpsReadData(1)
        CChromManager.closenpwh()
        CChromManager.clearData()
    }

    // 图
    Rectangle{      // 背景白板
        id: layout_rect
        radius: 5*dp
        height: parent.height - y - 15*dp
        width: parent.width - 2*x
        x: 15*dp; y: 55*dp
    }
    property int minTickSpacing: showDetails ? 150*dp:50*dp      // 网格最小间距
    Text {
        x:20*dp
        y:15*dp
        text: qsTr("能谱图")
        font.bold: true
        font.pixelSize: config.fontsize_1
    }
    CustomButton{
        x:parent.width-340*dp
        y:15*dp
        defaultMode1: true
        width: 100*dp
        height: 30*dp
        title: "读取"
        onReleased: {
            CChromManager.opennpwh()
            CChromManager.onStartExperiment()
            CMaintenance.operationCpsReadData(0)
        }
    }
    CustomButton{
        x:parent.width-230*dp
        y:15*dp
        defaultMode1: true
        width: 100*dp
        height: 30*dp
        title: "停止"
        onReleased: {
            CChromManager.closenpwh()
            CChromManager.onEndExperiment()
            CMaintenance.operationCpsReadData(1)
        }
    }
    CustomButton{
        x:parent.width-120*dp
        y:15*dp
        defaultMode1: true
        width: 100*dp
        height: 30*dp
        title: "清除"
        onReleased: {
            CChromManager.clearData()
        }
    }



    CustomChart{
        id: chart
        maxY: 800
        cChartInterface: CChromChart
        height: parent.height - y - 40*dp
        width: parent.width - 2*x
        title_fontsize: config.fontsize_1
//        contentWidth: Math.max(canvasWidth, tickCountX * minTickSpacing)
        x: 40*dp; y: 65*dp
        margin: 0
    }
    Connections{
        target: CChromManager
        onSigStartCollect: {
            // 开始收集
        }onSigEndCollect: {
            // 结束收集
        }
    }



}
